package com.example.hadoop.mapreduce.dbscan;

import com.example.hadoop.others.Helper;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URISyntaxException;

public class DbscanApp {
    public static void main(String[] args) throws InterruptedException, IOException, URISyntaxException {
        int minPoints = 10;
        double eps = 3.0;
        Configuration configuration = Helper.getConfiguration();
        FileSystem fileSystem = Helper.getFileSystem();
        Path dataPath = new Path("/cluster/data.txt");
        Path localPath = new Path("./cluster.data.txt");
        boolean isExists = fileSystem.exists(dataPath);
        if (!isExists) {
            System.out.println("file not exits");
            Helper.generateData(100, true);
            fileSystem.copyFromLocalFile(localPath, dataPath);
        }

        Path dbscanBasePath = new Path("/cluster/dbscan");
        isExists = fileSystem.exists(dbscanBasePath);
        if (isExists) {
            fileSystem.delete(dbscanBasePath, true);
        }
        fileSystem.mkdirs(dbscanBasePath);
        DbscanUtils.writeParameters(fileSystem, "/cluster/dbscan/params.txt", eps, minPoints);
    }
}
